package com.nhc.model;

import com.nhc.database.dbmodel.SystemAllInfo;
import com.nhc.database.manager.SystemCenter;

import zuo.biao.library.util.JSON;

public class TripDataFileHandle {

    private static TripDataFileHandle instance = new TripDataFileHandle();
    public TripDatainfo mTripDatainfo = new TripDatainfo();

    public static TripDataFileHandle getInstance() {
        return instance;
    }

    public TripDataFileHandle() {
        load();
    }

    private String TRIPDATA = "TRIPDATA";

    public void save() {
        String strTripDatainfo = JSON.toJSONString(mTripDatainfo);
        SystemAllInfo sInfo = SystemCenter.getInstance().getSysInfo(TRIPDATA);
        if (sInfo == null) {
            sInfo = new SystemAllInfo(null, TRIPDATA, strTripDatainfo);
        } else {
            sInfo.setContent(strTripDatainfo);
        }
        SystemCenter.getInstance().saveSysInfo(sInfo);
    }

    public void load() {
        SystemAllInfo sInfo = SystemCenter.getInstance().getSysInfo(TRIPDATA);
        if (sInfo == null) {
            return;
        }
        String strTripDatainfo = sInfo.getContent();
        if (strTripDatainfo.length() > 1) {
            try {
                com.alibaba.fastjson.JSONObject data = JSON.parseObject(strTripDatainfo);
                if (data != null) {
                    mTripDatainfo = JSON.parseObject(data, TripDatainfo.class);
                }
            } catch (Exception e1) {

            }
        }
    }

}